package com.deng.etl.common;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.deng.common.SQLHelper;
import com.deng.common.vo.ClassTypeVo;
import com.deng.maintenance.vo.ItemWeightVo;
import com.deng.util.DateTools;

public abstract class EtlLog extends SQLHelper {

	//用来记录抓取失败的信息
	
	public void addTableLog(Connection targetConn,String name,Date stat_time){
		try{
			StringBuffer sb = new StringBuffer();
			
			PreparedStatement pst = targetConn.prepareStatement("insert into t_sys_etl_data_log" +
					"(name,error_info,stat_time)" +
					"values(?,?,?)");
			pst.setString(1, name);
			pst.setString(2, sb.toString());
			pst.setDate(3, DateTools.UDtoSD(stat_time));
			pst.execute();
			pst.close();
		}catch(Exception ex){
			ex.printStackTrace();
		}
		
	}
	public void addDataLog(Connection targetConn,String name,String stat_time,ResultSet rs){
		try{
			StringBuffer sb = new StringBuffer();
			ResultSetMetaData rsmd = rs.getMetaData();
			int count=rsmd.getColumnCount();
			String[] names=new String[count];
			for(int i=0;i<count;i++){
				sb.append(names[i]+"="+rs.getString(names[i])+";");
			}
			PreparedStatement pst = targetConn.prepareStatement("insert into t_sys_etl_data_log" +
					"(name,error_info,stat_time)" +
					"values(?,?,?)");
			pst.setString(1, name);
			pst.setString(2, sb.toString());
			pst.setDate(3, DateTools.UDtoSD(DateTools.stdJustDate(stat_time)));
			pst.execute();
			pst.close();
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
	
	public static void finishOneTaskETLLog(Connection targetConn,String name,String stat_time){
		try{
//			PreparedStatement pst = targetConn.prepareStatement("update t_sys_etl_daily" +
//					"	set stat_time = '"+stat_time+"'," +
//						"	finish_time = '"+DateTools.dtsWithHour(new Date())+"'," +
//						"	status= 0 " +
//						"	where name = '"+name+"'");
//			pst.executeUpdate();
//			pst.close();
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
	public void errorOneTaskETLLog(Connection targetConn,String name,String stat_time){
		try{
			PreparedStatement pst = targetConn.prepareStatement("update t_sys_etl_daily" +
					"	set finish_time = '"+DateTools.dtsWithHour(new Date())+"'," +
						"	status= 2 " +
						"	where name = '"+name+"'");
			pst.executeUpdate();
			pst.close();
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
	public static void progressOneTaskETLLog(Connection targetConn,String name,String stat_time){
		try{
//			PreparedStatement pst = targetConn.prepareStatement("update t_sys_etl_daily" +
//					"	set " +
//						"	status= 1 " +
//						"	where name = '"+name+"'");
//			pst.executeUpdate();
//			pst.close();
		}catch(Exception ex){
			ex.printStackTrace();
		}
	}
}
